//
//  XCTabBar.m
//  weibo-OC
//
//  Created by 1 on 16/3/6.
//  Copyright © 2016年 1. All rights reserved.
//

#import "XCTabBar.h"

@interface XCTabBar ()

@property (nonatomic,strong) UIButton *addBtn;

@end

@implementation XCTabBar

- (UIButton *)addBtn{
    
    if(!_addBtn){
        
        _addBtn = [[UIButton alloc]init];
        
        [_addBtn  setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        
        [_addBtn  setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        
        [_addBtn  setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [_addBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];

    
    }
    
    return _addBtn;
}

- (instancetype)init{
    
    if(self = [super init]){
        

        [self addSubview:self.addBtn];

    }
    
    return self;
}

- (void)layoutSubviews{

    CGFloat w = [UIScreen mainScreen].bounds.size.width / 5;
    CGFloat h = self.bounds.size.height;
    CGRect rect = CGRectMake(0, 0, w, h);

    
    //定义一个索引
   __block CGFloat index = 0;
    
    [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
       
        if ([obj isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            obj.frame = CGRectOffset(rect, index * w - w, 0);
        }
        
        if (index == 2) {
            index ++;
        }
        
        index++;
        
    }];
    
        self.addBtn.frame = CGRectOffset(rect, 2 * w, -h/2);
}


@end
